#ifndef TRAVELLING_STRUCT_HH
#define TRAVELLING_STRUCT_HH 1


#include <string>
#include <iostream>
#include <vector>
#include "otl8.hpp"
#include "datetime_period.hpp"

static const char*  travelling_struct_s = "SELECT ID, TRAVELLING_DATE, KM, CAR_ID, TRAVELLING_TYPE_ID, ACTIVITY_ID, ESTIMATED_CONSUMPTION FROM TRAVELLING_STRUCT";

static const char*  travelling_struct_i = "INSERT INTO TRAVELLING_STRUCT ( ID, TRAVELLING_DATE, KM, CAR_ID, TRAVELLING_TYPE_ID, ACTIVITY_ID, ESTIMATED_CONSUMPTION )VALUES(:f1<int>, :f2<date>, :f3<float>, :f4<int>, :f5<int>, :f6<int>, :f7<float>)";

static const char* travelling_struct_c = "CREATE TABLE TRAVELLING_STRUCT ( ID INTEGER , TRAVELLING_DATE  , KM FLOAT , CAR_ID INTEGER , TRAVELLING_TYPE_ID INTEGER , ACTIVITY_ID INTEGER , ESTIMATED_CONSUMPTION FLOAT )";
class travelling_struct
{



public:
travelling_struct():_id(0), _travelling_date(boost::gregorian::not_a_date_time), _km(0), _car_id(0), _travelling_type_id(0), _activity_id(0), _estimated_consumption(0){_select=travelling_struct_s;_insert=travelling_struct_i;_create=travelling_struct_c;}


travelling_struct(int a__id, boost::gregorian::date a__travelling_date, float a__km, int a__car_id, int a__travelling_type_id, int a__activity_id, float a__estimated_consumption):_id(a__id) , _travelling_date(a__travelling_date) , _km(a__km) , _car_id(a__car_id) , _travelling_type_id(a__travelling_type_id) , _activity_id(a__activity_id) , _estimated_consumption(a__estimated_consumption) {_select=travelling_struct_s;_insert=travelling_struct_i;_create=travelling_struct_c;}


int id(){return  _id;}
void set_id(int a__id){ _id = a__id;}


boost::gregorian::date travelling_date(){return  _travelling_date;}
void set_travelling_date(boost::gregorian::date a__travelling_date){ _travelling_date = a__travelling_date;}


float km(){return  _km;}
void set_km(float a__km){ _km = a__km;}


int car_id(){return  _car_id;}
void set_car_id(int a__car_id){ _car_id = a__car_id;}


int travelling_type_id(){return  _travelling_type_id;}
void set_travelling_type_id(int a__travelling_type_id){ _travelling_type_id = a__travelling_type_id;}


int activity_id(){return  _activity_id;}
void set_activity_id(int a__activity_id){ _activity_id = a__activity_id;}


float estimated_consumption(){return  _estimated_consumption;}
void set_estimated_consumption(float a__estimated_consumption){ _estimated_consumption = a__estimated_consumption;}


travelling_struct & operator=( const travelling_struct & x)
{
	_id =  x._id;
	_travelling_date =  x._travelling_date;
	_km =  x._km;
	_car_id =  x._car_id;
	_travelling_type_id =  x._travelling_type_id;
	_activity_id =  x._activity_id;
	_estimated_consumption =  x._estimated_consumption;
	return *this;
}


bool operator==( const travelling_struct & x)
{
	return 	_id ==  x._id &&
	_travelling_date ==  x._travelling_date &&
	_km ==  x._km &&
	_car_id ==  x._car_id &&
	_travelling_type_id ==  x._travelling_type_id &&
	_activity_id ==  x._activity_id &&
	_estimated_consumption ==  x._estimated_consumption;
}


friend std::istream& operator >> (std::istream& ist, travelling_struct & t)
{
	if (!(ist >> t._id)) return ist;
	if (!(ist >> t._travelling_date)) return ist;
	if (!(ist >> t._km)) return ist;
	if (!(ist >> t._car_id)) return ist;
	if (!(ist >> t._travelling_type_id)) return ist;
	if (!(ist >> t._activity_id)) return ist;
	if (!(ist >> t._estimated_consumption)) return ist;

	return ist;
}

friend std::ostream& operator << (std::ostream& ost, travelling_struct & t)
{
	ost << t._id << " ";
	ost << t._travelling_date << " ";
	ost << t._km << " ";
	ost << t._car_id << " ";
	ost << t._travelling_type_id << " ";
	ost << t._activity_id << " ";
	ost << t._estimated_consumption << " ";

	return ost;
}

/*
friend otl_stream& operator >> (otl_stream& ist, travelling_struct & t)
{
	ist >> t._id;
	ist >> t._travelling_date;
	ist >> t._km;
	ist >> t._car_id;
	ist >> t._travelling_type_id;
	ist >> t._activity_id;
	ist >> t._estimated_consumption;

	return ist;
}

friend otl_stream& operator << (otl_stream& ost, travelling_struct & t)
{
	ost << t._id ;
	ost << t._travelling_date ;
	ost << t._km ;
	ost << t._car_id ;
	ost << t._travelling_type_id ;
	ost << t._activity_id ;
	ost << t._estimated_consumption ;

	return ost;
}
*/

std::string select_stmt() { return _select; }
std::string insert_stmt() { return _insert; }
std::string create_stmt() { return _create; }


private:

	int	_id;
	boost::gregorian::date	_travelling_date;
	float	_km;
	int	_car_id;
	int	_travelling_type_id;
	int	_activity_id;
	float	_estimated_consumption;
	std::string _create;
	std::string _select;
	std::string _insert;
char buf[128];
};
#endif
